<template>
	<view class="cash">
		
	    <view class=""  style="background: #fff;display: flex;align-items: center; padding: 20rpx 20rpx 0 20rpx;">
	    	<u-alert-tips type="warning" show-icon :description="description1"></u-alert-tips>
	    </view>
		<view class="H10"></view>
		<view class='money'>
			<view class='ktx text-bold' style="font-size: 40rpx;">可提现金额：{{keti_money}}元</view>
		</view>
		
		
		<view class='jine' style="display: flex;flex-direction: row;align-items: center;">
			<view class="jine_01">请输入提现金额:¥</view>
			<view class="jine_02">
				<input class="uni-input" style="font-size: 40rpx;" v-model="money" type="number" maxlength="11" />
			</view>
		</view>
		
		
		<view class='txfy' style="display: flex;align-items: center;color: #999999;">
			<view style="display: flex;justify-content: space-between;width: 100%;">
				<view class='txfy_02_l'>每日限额1000元</view>
				<view class='txfy_02_r'>及时到账</view>
			</view>
		</view>	
	
		
		<view class="login__info__item__button tn-cool-bg-color-15--reverse" hover-class="tn-hover" :hover-stay-time="150" @click="tixian()">提交</view>
		
		
		
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	const db = uniCloud.database()
	export default {
		data() {
			return {
				description1: '切记：目前提现采取提现到微信余额的方式，即自己绑定的微信，平台目前支持每天最高一次上限1000元且每天累计提现1000元！',
				name:"",
				money:0,
				checked: true,
				store_id: "",
				islogin: false,
				all_money: 0,
				tixian_money: 0,
				keti_money: 0, //可提现金额
				cart_num: "",
				istijiao:false,
			};
		},
		computed: {

		},
		onLoad(options) {
			let that =this
			this.openid = options.openid
			// that.name = options.name
			that.keti_money = options.money
			console.log("openid",that.openid)
			console.log("keti_money",that.keti_money)
		},
		components: {},
		methods: {
			tixian(){
				let that = this
				console.log("提交状态",this.istijiao)
				if(that.istijiao){
					//已经提交了一次请求，提示不能重复提交
					uni.showModal({
						title:"温馨提示",
						content:"您已在本页面提交了一次提现请求了，已无法继续提交"
					})
					return
				}
				that.istijiao=true
				if(this.keti_money<=0||Number(this.money)>Number(this.keti_money)){
					uni.showModal({
						title:"您在食小助中获得的可提现收益不足，无法提现",
						success(res) {
							if(res.confirm){
								return
							}
						}
					})
				}else{
					if(Number(this.money)>1000){
						uni.showModal({
							title:"系统限额1000元每日",
							success(res) {
								if(res.confirm){
									return
								}
							}
						})
					}else{
						uni.showModal({
							title:"您是否提现"+this.money+"？",
							success(res) {
								uni.showLoading({
									title:"正在提交中"
								})
								// console.log("点击信息",res)
								if(res.confirm){
									let myDate = (new Date()).Format("yyyy-MM-dd hh:mm:ss");
									uni.request({
										url:"https://zback.shixiaozhu.work/ShixiaozhuTest/settlement/merchantUser",
										header: {
											'content-type': 'application/x-www-form-urlencoded;charset:utf-8'
										},
										method: "POST",
										data: {
											"openId": that.openid,
											"amount": that.money,
											"remark":"提现",
										},
										success(res) {
											if(res.data.status==200){
												uni.hideLoading()
												var message = "用户提现";
												var type = 2;
												var tips = "";
												db.collection('moneyorder')
													.add({
														data: {
															openid: that.openid,
															message: message,
															money: that.money,
															tips: that.tips,
															time: new Date().getTime(),
															type:type
														}
													})
													.then((res) => {
														that.$refs.uToast.show({
															title: '提现请求已发出，请在微信里注意查收~',
															type: 'success'
														})
														setTimeout(function() {
															uni.navigateBack();
														}, 800);
													})
											}else{
												uni.hideLoading()
												that.$refs.uToast.show({
													title: '你今日提现已经超过了1000元限额，如有疑问请联系管理员',
													type: 'error'
												})
											}
										}
									})
									//2.TODO:向管理员发送模版消息，然后打钱，最后在管理员页面上进行对提现记录进行操作
								}else{
									uni.hideLoading()
									return
								}
							}
						})
					}
				}
			
			}
		
		}
	};
</script>

<style lang="scss">
	.login__info__item__button {
		margin: 60rpx auto;
		width: 690rpx;
		height: 80rpx;
		padding: 20rpx;
		border-radius: 10rpx;
		text-align: center;
		font-size: 32rpx;
		font-weight: bold;
		justify-content: center;
		align-items: center;
		margin-bottom: 20rpx;
	}
	
	
	.cash {
		background-color: #f5f5f5;
		height: 100vh;
		font-size: 28rpx;

		.txz {
			padding: 30rpx 20rpx;
			background-color: #fff;
		}

		.money {
			background-color: #fff;
			padding: 20rpx;
		}

		.ktx {
			font-size: 24rpx;
			color: #949398;
		}

		.jine {
			display: flex;
			background-color: #fff;
			padding: 18rpx 20rpx;
			border-bottom: 2rpx solid #F8F8F8;
			border-top: 2rpx solid #F8F8F8;
		}

		.jine_01 {
			padding: 14rpx 20rpx 0 0;
			font-size: 24rpx;
			font-weight: bold;
		}

		.kg {
			background-color: #fff;
			display: flex;
			justify-content: space-between;
			padding: 18rpx 0rpx 14rpx 20rpx;
		}

		.kg_l {
			padding-top: 16rpx;
		}

		.khh {
			background-color: #fff;
			border-top: 2rpx solid #F8F8F8;
			padding: 34rpx 30rpx 24rpx;
		}

		.txfy {
			width: 100%;
			background-color: #fff;
			padding: 10rpx 20rpx;
			font-size: 24rpx;
		}

		.txfy_01 {
			width: 100%;
			display: flex;
			justify-content: space-between;
			border-top: 2rpx solid #F8F8F8;
			padding: 20rpx 0 10rpx;
		}

		.txfy_02 {
			display: flex;
			justify-content: space-between;
			color: #B8B8BC;
			padding-bottom: 20rpx;
		}

		.btn {
			margin: 60rpx 20rpx 20rpx;
			background-color: #FF976A;
			height: 86rpx;
			line-height: 86rpx;
			text-align: center;
			border-radius: 40rpx;
			color: #fff;
		}
	}
</style>
